﻿using System.Collections.Generic;
using System.Linq;
using EPiServer.Find;

namespace JoelAbrahamsson.Web.ViewModels
{
    public class SearchResult
    {
        private SearchResult()
        {
        }

        public static SearchResult Create(SearchResults<SearchHit> searchResponse, string query, string moreLink)
        {
            var product = new SearchResult();
            product.Hits = searchResponse;
            product.Query = query;
            product.MoreHitsExists = searchResponse.TotalMatching > searchResponse.Hits.Count();
            product.MoreLink = moreLink;

            return product;
        }

        public static SearchResult Empty()
        {
            var product = new SearchResult();

            return product;
        }

        public IEnumerable<SearchHit> Hits { get; private set; }

        public string Query { get; private set; }

        public bool MoreHitsExists { get; private set; }

        public string MoreLink { get; private set; }

        public void StartFromHitNumber(int hitNumber)
        {
            Hits = Hits.Skip(hitNumber);
        }
    }
}